package ljx;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;

@WebServlet("/login_cookie")
public class login_cookie extends HttpServlet {
    private String myusername="admin";
    private String mypassword="123456";

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username=req.getParameter("username");
        String password=req.getParameter("password");
        if (username.equals(myusername)&&password.equals(mypassword)){
            Cookie cookie = new Cookie("name", username);
            cookie.setMaxAge(60*60*24*7);//有效期为一周
            resp.addCookie(cookie);
            req.getRequestDispatcher("welcome_cookie.jsp").forward(req,resp);
        }
        else{
            resp.sendRedirect("logincookie.jsp");
        }

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {


    }
}
